package com.lhb.boyixue.base;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author 86131
 * @version 1.0
 * @description 全局异常处理器
 * @date 2025/5/24 下午10:56
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

        @ExceptionHandler(value = SQLIntegrityConstraintViolationException.class)
        public UnifyResponseObject exception(SQLIntegrityConstraintViolationException e) {
            log.error(e.getMessage(), e);
            return UnifyResponseObject.success(e.getMessage());
        }

    @ExceptionHandler(value = RuntimeException.class)
    public UnifyResponseObject exception(RuntimeException e) {
        log.error(e.getMessage(), e);
        return UnifyResponseObject.success(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public UnifyResponseObject exception(Exception e) {
        log.error(e.getMessage(), e);
        return UnifyResponseObject.success(e.getMessage());
    }

}
